#pragma once
#ifndef ATOMICARRAY_H
#define ATOMICARRAY_H

#include <atomic>

namespace ParticleEngine
{
	template <class T, size_t N> class AtomicArray
	{
	public:
		AtomicArray<T, N>(void) :
			ListCount(0)
		{
			Item = new T[N];
		};
		~AtomicArray()
		{
			delete [] Item;
		};
		void Add(T NewItem)
		{
			const size_t ListPos = std::atomic_fetch_add(&ListCount, 1);
			Item[ListPos] = NewItem;
		};
		size_t Count(void)
		{
			return ListCount;
		};
		void Reset(void)
		{
			ListCount = 0;
		};
		T operator[] (const size_t n)
		{
			return Item[n];
		};
	private:
		std::atomic<size_t> ListCount;
		T *Item;
	};
}
#endif